﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using Objects;
using BAL;

public partial class Admin_UCControls_UCLoaiThe : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            GetLoaiThe();
          
        }
    }

    public static List<LoaiThe> ListLoaiThe = new List<LoaiThe>();


    public void GetLoaiThe()
    {
        ListLoaiThe = BALLoaiThe.GetAllItem();
        GridLoaiThe.DataSource = ListLoaiThe;
        GridLoaiThe.DataBind();
    }

    protected void btnThemMoi_Click(object sender, EventArgs e)
    {
        Session.Remove("ItemLoaiThe");
        Response.Redirect("../Admin/LoaiThe_Update.aspx");
    }


    protected void GridLoaiThe_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Sua")
        {
        
            foreach (LoaiThe Item in ListLoaiThe)
            {
                if (Item.Id == Convert.ToInt16(e.CommandArgument))
                {
                    Session.Add("ItemLoaiThe", Item);
                }
            }

            Response.Redirect("../Admin/LoaiThe_Update.aspx");
            
        }

        if (e.CommandName == "Xoa")
        {
            int item;
           // item = BALLoaiThe.Delete_LoaiThe(Convert.ToInt32(e.CommandArgument.ToString()));

            foreach (LoaiThe Item in ListLoaiThe)
            {
                if (Item.Id == Convert.ToInt16(e.CommandArgument))
                {
                    item = BALLoaiThe.Update_LoaiThe(Int32.Parse(Item.Id.ToString()), Item.LoaiTheDK.ToString(), Item.TenThe.ToString(), Item.GhiChu.ToString(), -1, Item.SapXep);
            
                }
            }
                
            GetLoaiThe();
        }

    }
}
